package com.ddwl.user.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.user.AuditConfigBo;
import com.ddwl.schema.bo.user.AuditConfigPageBo;
import com.ddwl.schema.bo.user.AuditConfigUpdateBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.user.AuditConfigVo;
import com.ddwl.user.service.AuditConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Author hemiaojun
 * @Date 2020/9/29 11:18
 */
@RequestMapping("/auditConfig")
@RestController
@Api(tags = "审核配置")
public class AuditConfigController extends BaseController {

    @Resource
    private AuditConfigService auditConfigService;

    @PostMapping("/add")
    @ApiOperation("新增配置")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<AuditConfigVo> add(@Valid @RequestBody AuditConfigBo bo){
        AuditConfigVo vo=auditConfigService.add(bo);
        return RestVo.ok(vo);
    }

    @PostMapping("/checkStatus")
    @ApiOperation("检查状态")
    public RestVo<Integer> checkStatus(@RequestBody AuditConfigBo bo){
        Integer status=auditConfigService.checkStatus(bo);
        return RestVo.ok(status);
    }

    @PostMapping("/update")
    @ApiOperation("修改配置")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo update(@Valid @RequestBody AuditConfigUpdateBo bo){
        auditConfigService.update(bo);
        return RestVo.ok();
    }

    @PostMapping("/delete")
    @ApiOperation("删除配置")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo delete(@RequestParam("id") String id){
        auditConfigService.delete(id);
        return RestVo.ok();
    }

    @PostMapping("/page")
    @ApiOperation("分页查询配置")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<PageVo<AuditConfigVo>> page(@RequestBody PageBo<AuditConfigPageBo> pageBo){
        PageVo<AuditConfigVo> pageVo=auditConfigService.page(pageBo);
        return RestVo.ok(pageVo);
    }

    @PostMapping("/changeId")
    @ApiOperation("把id反转成时间戳")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo changeId(){
        auditConfigService.changeId();
        return RestVo.ok();
    }

}
